<?php
require "Db\DbHelper.php";
require "Tools\WebResult.php";

use Tools\WebResult;
use Db\DbHelper;

$logged_user = $_SESSION['user'];

// 未登录
if (empty($logged_user)) {
    WebResult::JsonFail('please_login_first！');
}

// 查询当前登录用户的购物车
$db = DBHelper::createPDO();
$stmt = $db->prepare('select b.*, c.Quantity from cart as c left join book as b on c.book_id = b.id where user_id = ?');
$stmt->bindValue(1, $logged_user['id']);

$stmt->execute();

$row = $stmt->fetchall();

WebResult::JsonResult($row);